<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [1, 8, 6, 2, 5, 4, 8, 3, 7]

      function maxArea(arr) {
        let arr1 = []
        for (let i = 0; i < arr.length - 1; i++) {
          for (let j = i + 1; j < arr.length; j++) {
            arr1.push((j - i) * Math.min(arr[i], arr[j]))
          }
        }
        return Math.max(...arr1)
      }
      console.log(maxArea(arr));
    </script>
  </body>
</html>
